package com.boot.app.base.dto;

import com.boot.app.base.domain.BaseUser;
import com.boot.common.Global;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

public class UserDetailsImpl implements UserDetails {

    private BaseUser user;

    private List<GrantedAuthority> authorities;

    public UserDetailsImpl(BaseUser user) {
        this.user = user;
    }

    public UserDetailsImpl(BaseUser user, List<GrantedAuthority> authorities) {
        this.user = user;
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return Global.STATUS_1.getCode().equals(user.getStatus());
    }

    public BaseUser getUser(){
        return this.user;
    }

}
